package com.wiz.weixin.manager;

import javax.annotation.Resource;

import org.json.JSONException;
import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.wiz.weixin.common.Constant;
import com.wiz.weixin.tencent.vo.UserInfoVo;
import com.wiz.weixin.util.TencentUtil;

/***
 * 微信用户信息查询
 * @author xxy
 */
@Component("wxUserManager")
public class WxUserManager {
	
	//new GsonBuilder().disableHtmlEscaping().create()
	@Resource
	private Gson gson;
	@Resource
	private WxAccessManager wxAccessManager;
	
	/**得到客户的基本信息
	 * @throws JSONException */
	public UserInfoVo getUserInfo(String openId){
		String url = Constant.USER_INFO_URL;
		url = url.replace("TOKEN", WxAccessManager.getTencent_wx_token());
		url = url.replace("OPENID", openId);
		String result = TencentUtil.httpsRequest(url, "POST", null);
		if(result.indexOf("40001") >= 0){
			wxAccessManager.resetTempTask();
			return null;
		}
		return gson.fromJson(result, UserInfoVo.class);
	}

}
